<template>
  <div>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <el-breadcrumb separator="/">
          <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item><a href="/">添加口碑</a></el-breadcrumb-item>
        </el-breadcrumb>
      </div>
      <div>
        <el-form ref="form" :model="form" label-width="80px" :rules="myrules">
          <el-form-item label="姓名" prop="name">
            <el-input v-model="form.name"></el-input>
          </el-form-item>
          <el-form-item label="手机" prop="tel">
            <el-input v-model="form.tel"></el-input>
          </el-form-item>
          <el-form-item label="报备时间">
            <el-date-picker
              v-model="form.date"
              type="date"
              placeholder="选择日期"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item label="口碑来源">
            <el-select v-model="form.origin" placeholder="请选择口碑来源">
              <el-option label="毕业生" value="1"></el-option>
              <el-option label="朋友" value="2"></el-option>
              <el-option label="同事" value="3"></el-option>
              <el-option label="网络" value="4"></el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="备注">
            <el-input type="textarea" v-model="form.desc"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSubmit">立即添加</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-card>
  </div>
</template>

<script>
import { addkb } from '@/api/koubei';
export default {
  data() {
    return {
      form: {
        name: "",
        tel: "",
        origin: "",
        date: "",
        desc: "",
      },
      myrules: {
        name: [{ required: true, message: "请输入口碑姓名", trigger: "blur" }],
        tel: [
          { required: true, message: "请输入手机号码", trigger: "blur" },
          {
            pattern: /^1[3-9]\d{9}$/,
            message: "请输入正确的手机号码",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    onSubmit() {
      addkb(this.form).then((r) => {
          if (r.data.code === 200) {
              this.$message({
                  type: 'success',
                  message: '添加成功'
              })
          }
          this.$router.push('/home/kblist')
      })
    },
  },
};
</script>

<style lang="scss" scoped>
</style>